﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WebDS;
using WebUS;
using WebDS.CDBNames;
using IP.Core.IPCommon;
using System.Data;
using IP.Core.IPData.DBNames;
using IP.Core.IPData;
using IP.Core.IPUserService;

public partial class ChucNang_Ban_giao_thiet_bi : System.Web.UI.Page
{
    #region bienToanCuc    
    int m_id_bao_tri_thiet_bi;
    US_GD_BAO_TRI_NOI_DUNG m_us_gd_bao_tri_noi_dung = new US_GD_BAO_TRI_NOI_DUNG();
    DS_GD_BAO_TRI_NOI_DUNG m_ds_gd_bao_tri_noi_dung = new DS_GD_BAO_TRI_NOI_DUNG();
    #endregion

    protected void Page_Load(object sender, EventArgs e)
    {
        m_id_bao_tri_thiet_bi = Convert.ToInt32(Request.Cookies["Id"].Value);
        if (!IsPostBack)
        {
            Load_cbo_thiet_bi();
            LoadDataGridVewNoiDungCongTac();
        }
    }

    protected void Load_cbo_thiet_bi()
    {
        US_DM_THIET_BI v_us_dm_thiet_bi = new US_DM_THIET_BI();
        DS_DM_THIET_BI v_ds_dm_thiet_bi = new DS_DM_THIET_BI();
        
        v_us_dm_thiet_bi.FillDataset(v_ds_dm_thiet_bi);
        m_cbo_thiet_bi.DataSource = v_ds_dm_thiet_bi.DM_THIET_BI;
        m_cbo_thiet_bi.DataTextField = DM_THIET_BI.TEN_MAY;
        m_cbo_thiet_bi.DataValueField = DM_THIET_BI.ID;
        m_cbo_thiet_bi.DataBind();
        
        
    }

    protected void LoadDataGridVewNoiDungCongTac()
    {
        US_GD_BAO_TRI_NOI_DUNG v_us_gd_bao_tri_noi_dung = new US_GD_BAO_TRI_NOI_DUNG();
        DS_GD_BAO_TRI_NOI_DUNG v_ds_gd_bao_tri_noi_dung = new DS_GD_BAO_TRI_NOI_DUNG();

        v_us_gd_bao_tri_noi_dung.filldataset_gd_bao_tri_noi_dung_id_dot_bao_tri(m_id_bao_tri_thiet_bi, v_ds_gd_bao_tri_noi_dung);
        m_grv_dm_su_co.DataSource = v_ds_gd_bao_tri_noi_dung;
        m_grv_dm_su_co.DataBind();
    }

    protected void xoa_form()
    {
        m_txt_ma_loi.Text = "";
        m_txt_model_may.Text = "";
        m_txt_noi_dung_loi.Text = "";
        m_txt_phuong_phap_khac_phuc.Text = "";
        m_txt_tinh_trang_may_sau_khi_sua.Text = "";
    }

    protected void form_2_us_object()
    {
        m_us_gd_bao_tri_noi_dung.strMA_LOI = m_txt_ma_loi.Text;
        m_us_gd_bao_tri_noi_dung.strNOI_DUNG_LOI = m_txt_noi_dung_loi.Text;
        m_us_gd_bao_tri_noi_dung.strPHUONG_PHAP_KHAC_PHUC = m_txt_phuong_phap_khac_phuc.Text;
        m_us_gd_bao_tri_noi_dung.strTINH_TRANG_SAU_SUA = m_txt_tinh_trang_may_sau_khi_sua.Text;
        m_us_gd_bao_tri_noi_dung.dcID_SN_THIET_BI = Convert.ToInt32(m_cbo_thiet_bi.Text);
        m_us_gd_bao_tri_noi_dung.dcID_DOT_BAO_TRI = m_id_bao_tri_thiet_bi;
    }


    protected void m_btn_them_su_co_moi_Click(object sender, EventArgs e)
    {
        form_2_us_object();        
        try
        {
            m_us_gd_bao_tri_noi_dung.Insert();
            LoadDataGridVewNoiDungCongTac();
            xoa_form();
        }
        catch (Exception v_e)
        {
            CSystemLog_301.ExceptionHandle(this, v_e);            
        }        
    }
    protected void m_btn_tiep_tuc_Click(object sender, EventArgs e)
    {
        Response.Cookies["Id"].Value = m_id_bao_tri_thiet_bi.ToString();
        Response.Redirect("~/ChucNang/BaoTriThietBi/Linh_kien.aspx");
    }
}